using System.Collections.Generic;

namespace RikMigrations
{
    public class View
    {
        internal DbProvider provider;

        List<Command> commands = new List<Command>();

        #region Properties
        private string name;
        public string Name
        {
            get { return name; }
        }

        private bool isCreating;
        public bool IsCreating
        {
            get { return isCreating; }
        }

        private string script;
        public string Script
        {
            get { return script; }
            set { script = value; }
        }
        #endregion

        public View(DbProvider provider, string name, bool createNew, string script)
		{
			this.provider = provider;
			this.name = name;
            this.script = script;
			if (createNew)
				commands.Add(provider.GetCreateViewCommand(this));
			isCreating = createNew;
		}

        public void Save()
        {
            foreach (Command cmd in commands)
                cmd.Execute(provider);
            commands.Clear();
            isCreating = false;
        }
    }
}